package hu.myai.indicators.util;

import hu.myai.api.indicators.AbstractTrend;
import hu.myai.model.TrendLineVO;

/**
 * Provides Fibonacci levels
 *
 * @author bozbalint
 *
 * */
public class Fibonacci extends AbstractTrend {

    private double fromValue;
    private double toValue;

    // fibonacci levels
    public static final double[] rowLevels = { 0.0, 0.236, 0.382, 0.5, 0.618, 0.764, 1.0 };

    /**
     * @param fromValue
     *            the 0% level of the fibonacci
     * @param toValue
     *            the 100% level of the fibonacci
     * @param toTime
     *            the timestamp when 100 level occurred; any value if tangent is
     *            0.
     * @param tangens
     *            the angle to the fibonacci trend channel; 0 if it is
     *            horizontal
     */
    public Fibonacci(double fromValue, double toValue, int toTime, double tangens) {
        super();
        this.fromValue = fromValue;
        this.toValue = toValue;

        // generate level list
        for (int i = 0; i < rowLevels.length; i++)
            levelList.add(new TrendLineVO((toValue - fromValue) * rowLevels[i] + fromValue, toTime, tangens));
    }

    /**
     * @return the fromValue
     */
    public double getFromValue() {
        return fromValue;
    }

    /**
     * @return the toValue
     */
    public double getToValue() {
        return toValue;
    }

    @Override
    public String toString() {
        return "[Fibonacci=" + fromValue + "," + toValue + "]";
    }
}
